/*
 * @Author: yangzonglong
 * @Date: 2020-06-01 11:14:08
 * @version: v1.0.0
 * @Descripttion: 
 * @LastEditors: 871387321@qq.com 871387321@qq.com
 * @LastEditTime: 2023-10-21 16:04:37
 * @Auditor: 
 */
import React, { ReactNode } from 'react';
import { TableProps as AntdTableProps, ColumnProps as AntdColumnProps } from 'antd/lib/table';
import ApiQuery from './../../interface/apiQuery';

export type FormatProps = string | 'date' | 'time' | 'money';
export type SorterKeyType = Record<string, 'ascend' | 'descend'>
export type FixedProps = any | 'left' | 'right';

export type ExtraItemProps<RecordType> = {
  dataIndex: string;
  render(text: string, record: RecordType, index: number, extra?: any): React.ReactNode;
  headerRender?(): React.ReactNode;
  required?: boolean;
};

export interface ColumnProps<T> extends AntdColumnProps<T> {
  format?: FormatProps;
  sorter?: boolean,
  fixed?: FixedProps,
  tooltip?: boolean,
  filter?: boolean,
  filterDropdownFlag?: boolean, // 为true时 则会出现column筛选功能
  // 以下属性为worrkflow项目独有
  fontSize?: number;
  fontWeight?: number;
  backgroundColor?: string;
  color?: string;
  customizeStyleFlag?: boolean;
  sorterFn?: Function // 自定义列排序
}

export type ToolNode = () => ReactNode;

export interface TableProps<RecordType> extends AntdTableProps<RecordType> {
  columns: ColumnProps<RecordType>[];
  url?: string;
  extra?: ExtraItemProps<RecordType>[];
  query?: any;
  rowSelectionType?: 'radio' | 'checkbox';
  dataSource?: RecordType[];
  onDoubleClick?(record: RecordType): void;
  toolNode?: ToolNode, // 工具栏
  rowSelectionDisabled?(record: RecordType, index?: number): boolean;
  rowSelectionChange?(rowKeys: string[], rows: RecordType[], param?: any, curPageSelectedKeys?: string[]): void;
  reduceBoxHeight?: number; // 如传此值 计算分页条数时 会优先拿box height 减去 reduceBoxHeight
  onPageChange?(dataSource: any[], page: number): void;
  flat?: boolean; // 为true时 则全部显示数据 不计算分页与滚动条
  beforeUrlApi?: () => void;
  handleResult?(result: any): { rows: RecordType[], count: number; };
  limitMaxHeight?: boolean;
  onDoubleClick?(row: RecordType): void;
  autoLoad?: boolean;
  recordSort?: string;
  dfPageSizeOptions?: string[];
  setTabsCount?(count: number): void;
  treeStructure?: boolean;
  treeId?: string;
  treeParentId?: string;
  dataSourceChange?(dataSource: RecordType[]): void;
  virtualListFlag?: boolean;
  onRowStyleFn?(record: RecordType): any;
}

export type SizeProps = {
  width: number,
  height: number;
};

export interface TableRefProps {
  getSelectedRows(): any[],
  removeSelectedRowKeys(rowKeys: string[]): void;
  setSelectRowKeys(rowKeys: string[], rows?: any[]): void,
  getSelectRow(): any,
  setDefaultRow(k: any, row: any[]): void,
  getDataSource(): any[],
  onRefresh(): void;
  getQuery?(): ApiQuery;
  resetScroll(): void;
  setDataSource(dataSource: any[]): void
}

export interface SelectedRowKeys {
  [propName: number]: string[];
}


